package com.changwu.cwbase.temples.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.changwu.cwbase.R;
import com.changwu.cwbase.Constants;
import com.changwu.cwbase.base.FragmentBase;
import com.changwu.cwbase.bean.entity.User;
import com.changwu.cwbase.bean.model.UserModel;
import com.changwu.cwbase.bean.response.ResultResponse;
import com.changwu.cwbase.net.ApiM;
import com.changwu.cwbase.net.RxObserver;
import com.changwu.cwbase.net.RxSchedulers;
import com.changwu.cwbase.temples.adapter.TempleAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * Created by changuw on 2018/2/12.
 */

public class TempNetListFragment extends FragmentBase{
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private TempleAdapter adapter;
    private List<User> beans = new ArrayList<>();

    public static Fragment newInstance() {
        TempNetListFragment fragment = new TempNetListFragment();
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // reqMerchant("", 1);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fm_recyclerview, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
        adapter = new TempleAdapter();
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setLayoutManager(new LinearLayoutManager(activity));
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.tvName:
                        break;
                }

            }
        });
        req();
    }


    private void req() {
        JSONObject params = new JSONObject();
        params.put("uid", UserModel.getInstance().getUid());
        ApiM.getInstance().getUserService().getcode(params).compose(RxSchedulers.<ResultResponse>io_main()).subscribeWith(new RxObserver<ResultResponse>(TAG, 0) {
            @Override
            public void success(ResultResponse response) {
                if (response.errno == Constants.success) {

                } else {
                    ToastUtils.showShort(response.errmsg);
                }
            }
        });
    }

    private void initData() {
    }

    /* @OnClick({R.id.back})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
        }
    }*/

}
